package com.ceres.system.dao;

import com.ceres.system.pojo.Admin;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

@Component
public interface AdminMapper extends Mapper<Admin> {
    //@Insert("insert into t_checkgroup_checkitem values (#{checkgroup_Id},#{checkitem_Id})")

    /**
     * 插入用户id和角色id到关联表
     * @param roleId
     * @param adminId
     */
    @Insert("insert into t_user_role values(#{uid},#{rid})")
    void addAdminAndRole(@Param("rid") Integer roleId,@Param("uid") Integer adminId);

    /**
     * 根据用户id查询角色id
     * @param id
     * @return
     */
    @Select("select rid from t_user_role where uid=#{id}")
    Integer[] findRoleByAdmin(Integer id);

    /**
     * 根据用户id删除关联角色
     * @param id
     */
    @Delete("delete from t_user_role where uid=#{id}")
    void deleteRolesByAdminId(Integer id);

    /**
     * 根据登录名查询登录用户信息
     * @param username
     * @return
     */
    @Select("select * from t_user where username=#{username}")
    Admin findAdminByUsername(String username);
}
